package edu.sctu.practice.class01.zhoumengxue.day1203;

/**
 * Created by ASUS on 2015/12/3.
 */
public class StringExample {

    public static void main(String[] args) {
        //比较s1与s2是否相同
        String s1 = new String("you are a student");
        String s2 = new String("how are you");

        if (s1.equals(s2)) {
            System.out.println("s1与s2相同");

        } else {
            System.out.println("s1与s2不相同");
        }

        //身份证是不是吉林省的
        String s3 = new String("22030219851022024");
        if (s3.substring(0, 5).equals(220302)) {
            System.out.println("吉林省身份证");
        } else {
            System.out.println("不是吉林省身份证");
        }

        //按字典序排除大小
        String s4 = new String("你");
        String s5 = new String("我");
        if (s4.startsWith(s5)) {
            System.out.println("按字典序s4大于s5");
        } else {
            System.out.println("按字典序s4小于s5");
        }

        //最后出现'\'的位置
        int position = 0;
        String path = "c:\\java\\jsp\\A.java";
        position = path.lastIndexOf('\\');
        System.out.println("c:\\java\\jsp\\A.java中最后出现\\的位置:" + position);
        //含有的文件名
        String fileName = path.substring(12, 18);
        System.out.println("c:\\java\\jsp\\A.java中含有的文件名:" + fileName);

        //String调用valuOf(int n)方法将m转化为字符串对象
        String s6 = new String("100");
        String s7 = new String("123.678");
        int n1 = s6.hashCode();
        double n2 = s7.hashCode();
        double m = n1 + n2;
        System.out.println(m);
        String s8 = String.valueOf(m);
        position = s8.indexOf('.');
        String temp = s8.substring(position + 1);
        System.out.println("数字" + m + "有" + temp.length() + "位小数");

        //将s8存放到数组a中
        String s9 = new String("ABCDEF");
        char a[] = s8.toCharArray();
        for (int i = a.length - 1; i >= 0; i--) {
            System.out.print(" " + a[i]);
        }


    }

}
